<?php


namespace app\common\model\mysql;


use think\Model;

class User extends Model
{

    protected $autoWriteTimestamp = true;
    /**
     *
     *  根据用户名获取后端表的数据
     * @param $username
     * @return array|bool|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserByPhoneNumber($phoneNumber){
        if(empty($phoneNumber)){
            return false;
        }
        $where = [
            'phone_number' => trim($phoneNumber)
        ];
        $result =  $this->where($where)->find();
        return $result;
    }

    public function getUserById($id){
        $id = intval($id);
        if($id){
            return false;
        }
        return $this->find($id);
    }
    public function getUserByUsername($username){
        if(empty($username)){
            return false;
        }
        $where = [
            'username' =>$username
        ];
        return $this->where($where)->find();
    }
    public function updateById($id,$data){
        $id = intval($id);
        if(empty($id) || empty($data) || !is_array($data)){
            return false;
        }
        return $this->where(compact('id'))->save($data);
    }
}